from datetime import datetime
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
from applications.exts import db


# 优惠卷表
class Coupon(db.Model, UserMixin):
    __tablename__ = 'wx_coupon'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='优惠卷id')
    coupon_sn = db.Column(db.String(99), nullable=False, unique=True, comment='优惠号')
    coupon_name = db.Column(db.String(40), comment='优惠卷名称')
    coupon_type = db.Column(db.String(40), comment='1，新用户，2普通')

    minmoney = db.Column(db.Integer, comment='多少钱可以使用优惠卷')
    submoney = db.Column(db.Integer, comment='减多少钱')
    coupon_status = db.Column(db.Integer, default=1, comment='优惠卷状态')
    numbers = db.Column(db.Integer, comment='优惠卷数量')
    start_time = db.Column(db.DateTime, default=datetime.now(), comment='优惠卷创建时间')
    text = db.Column(db.String(60),comment='状态')
    end_time = db.Column(db.DateTime, comment='有效期')

    is_del = db.Column(db.Integer, default=0, comment='逻辑删除')

    wx_coupon_classifyid = db.Column(db.Integer, db.ForeignKey('wx_coupon_classify.id'), nullable=False, comment='设置外建')

    def __str__(self):
        return self.id


# 分类表
class Coupon_Class(db.Model, UserMixin):
    __tablename__ = 'wx_coupon_classify'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='商品分类表id')
    name = db.Column(db.String(30), nullable=False, unique=True, comment='分类名称')

    # coupon = db.relationship('Coupon', backref='wx_coupon_classifyid')

    def __str__(self):
        return self.name
